package com.mjl.shops.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


public abstract class BaseActivity extends AppCompatActivity {

    //伪沉浸式 只是设置状态栏背景颜色
    private static int BACK_COLOR = 1;

    //沉浸式 设置状态栏背景透明
    private static int BACK_STYLE =2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentViewBefore();
        setStateUi();
        setContentView(getViews());
        setViews();
        setDate();
    }

    //在加载布局之前设置界面样式
    protected abstract void setContentViewBefore();

    //加载状态栏样式
    protected  void setStateUi(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            Window window = getWindow();
            if (getStetaBackgroundStyle() == BACK_COLOR){
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.parseColor(getStateColor()));
            }else if (getStetaBackgroundStyle() == BACK_STYLE){
                window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
        }
    }

    //获取布局
    protected abstract int getViews();

    //初始化控件
    protected abstract void setViews();

    //初始化数据
    protected abstract void setDate();

    //状态栏背景颜色
    protected abstract String getStateColor();

    //设置状态栏样式（沉浸式 即状态栏颜色透明）
    protected abstract int getStetaBackgroundStyle();
}
